<template>
  <div class="student">
    <h1>学生姓名：{{name}}</h1>
    <h1>学生性别：{{sex}}</h1>
    <button @click="showMsg">点我输出学生姓名</button>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
    export default {
        name: "Student",
        data(){
          return{
            name:'李四',
            sex:'女'
          }
        },
        methods:{
          //消息发布
          showMsg(){
            pubsub.publish("getStudentName",this.name)
          }
        }
    }
</script>

<style scoped>
.student{
  background-color: pink;
}
</style>
